package com.cloudfun.campusshare.entity;

import com.cloudfun.campusshare.common.constant.CouponType;
import com.cloudfun.campusshare.common.constant.UserCouponStatus;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * Created by Huqin on 2020/5/29
 */
@Data
@Entity
@Table(name = "user_coupon")
@org.hibernate.annotations.Table(appliesTo = "user_coupon", comment = "用户领取的优惠券")
public class UserCouponEntity extends BaseEntity {

    @Id
    @GenericGenerator(name = "id_uuid", strategy = "uuid")
    @GeneratedValue(generator = "id_uuid")
    @Column(unique = true, columnDefinition = ("varchar(40) not null comment '主键uuid'"))
    private String id;

    @Column(columnDefinition = ("varchar(40) default null comment '优惠券id'"))
    private String couponId;

    @Column(unique = true, columnDefinition = ("varchar(32) not null comment '代金券编号'"))
    private String couponNo;

    @Column(columnDefinition = ("varchar(40) default null comment '活动id'"))
    private String promotionId;

    @Column(columnDefinition = ("varchar(40) not null comment '客户Id'"))
    private String userId;

    @Column(columnDefinition = ("varchar(20) not null comment '客户手机号'"))
    private String userPhone;

    @Column(name = "wash_point_id", columnDefinition = ("varchar(40) not null comment '洗衣点id'"))
    private String washPointId;

    @ManyToOne
    @JoinColumn(name = "wash_point_id", insertable = false, updatable = false)
    private WashPointEntity washPoint;

    @Column(columnDefinition = ("varchar(32) not null comment '优惠券类型'"))
    @Enumerated(EnumType.STRING)
    private CouponType couponType;

    @Column(columnDefinition = ("int(10) not null comment '金额'"))
    private Integer amount;

    @Column(columnDefinition = ("datetime not null comment '使用开始时间'"))
    private LocalDateTime startTime;

    @Column(columnDefinition = ("datetime not null comment '使用结束时间'"))
    private LocalDateTime endTime;

    @Column(columnDefinition = ("varchar(32) not null comment '状态'"))
    @Enumerated(EnumType.STRING)
    private UserCouponStatus status;

    @Column(columnDefinition = ("datetime default null comment '使用时间'"))
    private LocalDateTime useTime;

    @Column(columnDefinition = ("varchar(40) default null comment '订单id'"))
    private String orderId;

    @Column(columnDefinition = ("varchar(40) default null comment '订单号'"))
    private String orderNo;

    @Column(columnDefinition = ("varchar(40) default null comment '发券人id'"))
    private String issuerId;

    @Column(columnDefinition = ("varchar(64) default null comment '发券人名称'"))
    private String issuerName;

    @Column(columnDefinition = ("varchar(40) not null comment '所属商户Id'"))
    private String merchantId;
}
